package com.huawei.hwphy2d.physical.model;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import com.huawei.hwphy2d.physical.config.json.Config;
import com.huawei.hwphy2d.physical.util.AxisTranslater;
import com.huawei.hwphy2d.physical.util.BarrierParameters;
import o.fzf;
import o.fzp;
import o.fzs;
import o.fzt;
import o.fzw;
import o.fzy;
import o.gac;

public class Barrier {
    private fzt body;
    private Config config;
    private float h;
    private gac mWorld;
    private Paint paint = new Paint();
    private Size screenSize;
    private float w;
    private float x;
    private float y;

    public enum ORIENTATION {
        ORIENTATION_NONE,
        ORIENTATION_LEFT_RIGHT,
        ORIENTATION_TOP_BOTTOM
    }

    public Barrier(Config config, gac o_gac, Size size) {
        this.config = config;
        this.mWorld = o_gac;
        this.paint.setStrokeWidth(6.0f);
        this.paint.setStyle(Style.STROKE);
        this.paint.setColor(Color.parseColor("#1d8367"));
        this.screenSize = size;
    }

    public void build(float f, float f2, fzp o_fzp, int i, ORIENTATION orientation) {
        createRoundBounds(f, f2, o_fzp, i, orientation, null);
    }

    public fzt createStaticBarrier(float f, float f2, fzp o_fzp, Object obj) {
        this.w = f;
        this.h = f2;
        this.x = o_fzp.ˊ;
        this.y = o_fzp.ॱ;
        fzf o_fzf = new fzf();
        float transPositionToBody = AxisTranslater.transPositionToBody(f / 2.0f);
        float transPositionToBody2 = AxisTranslater.transPositionToBody(f2 / 2.0f);
        if (f2 >= this.screenSize.getHeight()) {
            transPositionToBody2 = AxisTranslater.transPositionToBody(f2);
        }
        if (f >= this.screenSize.getWidth()) {
            transPositionToBody = AxisTranslater.transPositionToBody(f);
        }
        o_fzf.ˏ(transPositionToBody, transPositionToBody2);
        fzy o_fzy = new fzy();
        o_fzy.ᐝ.ॱ = 2;
        o_fzy.ᐝ.ˊ = 4;
        o_fzy.ᐝ.ˏ = -2;
        fzt createBody = createBody(o_fzf, o_fzp, fzs.ˋ);
        this.body = createBody;
        return createBody;
    }

    public fzt createStaticBarrier(float f, float f2, int i, fzp o_fzp) {
        this.w = f;
        this.h = f2;
        this.x = o_fzp.ˊ;
        this.y = o_fzp.ॱ;
        fzf o_fzf = new fzf();
        o_fzf.ˏ(AxisTranslater.transPositionToBody(f / 2.0f), AxisTranslater.transPositionToBody(f2 / 2.0f));
        fzt createBody = createBody(o_fzf, o_fzp, i, fzs.ˋ);
        this.body = createBody;
        return createBody;
    }

    public void createRoundBounds(float f, float f2, fzp o_fzp, int i, ORIENTATION orientation, Object obj) {
        if (orientation == ORIENTATION.ORIENTATION_NONE || obj == null) {
            createStaticBarrier(f, f2, i, o_fzp);
            return;
        }
        if (orientation == ORIENTATION.ORIENTATION_LEFT_RIGHT) {
            createHorizontalBounds(f, this.screenSize.getHeight(), o_fzp, obj);
        }
        if (orientation == ORIENTATION.ORIENTATION_TOP_BOTTOM) {
            createVerticalBounds(this.screenSize.getWidth(), f2, o_fzp, obj);
        }
    }

    private fzt createBody(fzf o_fzf, fzp o_fzp, fzs o_fzs) {
        fzw o_fzw = new fzw();
        o_fzw.ॱ = o_fzs;
        o_fzw.ˎ.ˎ(AxisTranslater.transPositionToBody(o_fzp.ˊ + (this.w / 2.0f)), AxisTranslater.transPositionToBody(o_fzp.ॱ + (this.h / 2.0f)));
        fzy o_fzy = new fzy();
        o_fzy.ˎ = o_fzf;
        o_fzy.ˊ = 0.0016666667f;
        o_fzy.ˏ = BarrierParameters.FRICTION;
        o_fzy.ॱ = BarrierParameters.RESTITUTION;
        fzt ˊ = this.mWorld.ˊ(o_fzw);
        ˊ.ˋ(o_fzy);
        return ˊ;
    }

    private fzt createBody(fzf o_fzf, fzp o_fzp, int i, fzs o_fzs) {
        fzw o_fzw = new fzw();
        o_fzw.ॱ = o_fzs;
        o_fzw.ˎ(AxisTranslater.transPositionToBody((float) i));
        o_fzw.ˎ.ˎ(AxisTranslater.transPositionToBody(o_fzp.ˊ + (this.w / 2.0f)), AxisTranslater.transPositionToBody(o_fzp.ॱ + (this.h / 2.0f)));
        fzy o_fzy = new fzy();
        o_fzy.ˎ = o_fzf;
        o_fzy.ˊ = 0.0016666667f;
        o_fzy.ˏ = BarrierParameters.FRICTION;
        o_fzy.ॱ = BarrierParameters.RESTITUTION;
        fzt ˊ = this.mWorld.ˊ(o_fzw);
        ˊ.ˋ(o_fzy);
        return ˊ;
    }

    private void createHorizontalBounds(float f, float f2, fzp o_fzp, Object obj) {
        createStaticBarrier(f, f2, new fzp(o_fzp.ˊ, o_fzp.ॱ), obj);
    }

    private void createVerticalBounds(float f, float f2, fzp o_fzp, Object obj) {
        createStaticBarrier(f, f2, new fzp(o_fzp.ˊ, o_fzp.ॱ), obj);
    }

    public void release(fzt o_fzt) {
        this.mWorld.ॱ(this.mWorld.ˋ());
        this.mWorld = null;
    }

    public fzt getBody() {
        return this.body;
    }

    public void draw(Canvas canvas) {
        float ˋ = ((float) ((((double) this.body.ˋ()) / 3.141592653589793d) * 180.0d)) % 360.0f;
        RectF rectF = new RectF(this.x - (this.w / 4.0f), this.y, this.x + this.w, this.y + this.h);
        RectF rectF2 = new RectF((this.x - (this.w / 4.0f)) - 1.0f, this.y - 1.0f, (this.x + this.w) + 1.0f, (this.y + this.h) + 1.0f);
        canvas.save();
        canvas.rotate(ˋ, this.x + (this.w / 2.0f), this.y + (this.h / 2.0f));
        canvas.drawRect(rectF, this.paint);
        Paint paint = new Paint();
        paint.setStyle(Style.STROKE);
        paint.setStrokeWidth(4.0f);
        paint.setColor(-16711936);
        canvas.drawRect(rectF2, paint);
        canvas.restore();
    }
}
